package com.wframe.project.former.dataservices.integral;


import com.frame.database.JBaseDao;
import com.frame.database.JdataBean;
import com.frame.database.PageResult;
import com.wframe.project.jnd.util.PageBean;
import org.apache.commons.lang.StringUtils;
import org.glassfish.jersey.internal.util.collection.StringIgnoreCaseKeyComparator;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;


public class IntegralDao extends JBaseDao {

    public IntegralDao(){ super("wbuser"); }

    public PageResult queryIntegraList(JdataBean parms,int size,int pageno)throws Exception{
        String sql="SELECT u.ID id,c.`name` name,u.phone phone,u.source source,u.pricegrade pricegrade,u.grade grade,u.integral integral FROM wbuser u,wb_company c where u.id = c.userid";
        List parmlist = new ArrayList();
        if (parms !=null){
            if (StringUtils.isNotBlank(parms.getString("id"))) {
                sql += " and u.ID=?";
                parmlist.add(parms.getString("id"));
            }

            if (StringUtils.isNotBlank(parms.getString("name"))) {
                sql += " and c.`name` like ?";
                parmlist.add("%" + parms.getString("name") + "%");
            }
            if (StringUtils.isNotBlank(parms.getString("phone"))) {
                sql += " and u.phone = ?";
                parmlist.add(parms.getString("phone"));
            }
            if (StringUtils.isNotBlank(parms.getString("source"))) {
                sql += " and u.source =?";
                parmlist.add(parms.getString("source"));
            }
        }
        sql += " order by u.ID desc";
        return getSession().query2(sql,parmlist, size, pageno);
    }


    public PageResult getCompanyedByUid(String userid, int size, int pageno) throws Exception {
              String sql=" select userid,create_time,integral,content from wb_integral where userid=?";
        return getSession().query(sql,new Object[]{userid},size,pageno);
    }

    public JdataBean findIntegralId(String id) throws  Exception{
        String sql = " select ID,username,integral from wbuser where ID =?";
        return getSession().getObject(sql,new Object[]{id});
    }


}
